#include<bits/stdc++.h>
#define int long long 
#define mid ((l+r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+'0');	
}
const int N=5e5+5;
int n,m;
int a[N],L[N],R[N];
vector<pair<int,int> >asd,s,to[N];
void Init(){
	sort(asd.begin(),asd.end());
	s.push_back(asd[0]);
	for(int i=1;i<m;i++){
		if(asd[i].first==asd[i-1].first)continue; 
		while(s.size()&&s.back().second>=asd[i].second)s.pop_back();
		s.push_back(asd[i]);
	}
	m=s.size();
	int now=1;
	for(int i=0;i<m;i++){
		now=max(s[i].first,now);
		while(now<=s[i].second)L[now++]=i+1;
	}
	now=n;
	for(int i=m-1;i>=0;i--){
		now=min(s[i].second,now);
		while(now>=s[i].first)R[now--]=i+1;
	}
	for(int i=1;i<=n;i++)if(R[i])to[R[i]].push_back(make_pair(L[i],a[i]));
}
int f[N],tree[N<<2];
void build(int x,int l,int r){
	if(l==r)return void(tree[x]=f[l]);
	build(ls,l,mid),build(rs,mid+1,r);
	tree[x]=min(tree[ls],tree[rs]);
}
int query(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R)return tree[x];
	if(R<=mid)return query(ls,l,mid,L,R);
	else if(L>mid)return query(rs,mid+1,r,L,R);
	else return min(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));
}
void modify(int x,int l,int r,int W){
	if(l==r)return void(tree[x]=f[l]);
	if(W<=mid)modify(ls,l,mid,W);
	else modify(rs,mid+1,r,W);
	tree[x]=min(tree[ls],tree[rs]);
}
void sol(){
	memset(f,0x3f,sizeof f);
	f[0]=0;
	build(1,0,m);
	for(int i=1;i<=m;i++){
		for(auto E:to[i]){
			int j=E.first,w=E.second;
			f[i]=min(f[i],query(1,0,m,j-1,i-1)+w);
		}
		modify(1,0,m,i);
	}
}
signed main(){
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	m=read();asd.resize(m);
	for(int i=0;i<m;i++){
		asd[i].first=read();
		asd[i].second=read();
	}
	Init();
	sol();
	write(f[m]);
	return 0;
}
